package com.syq.play.impl;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;

import com.syq.play.R;
import com.syq.play.api.FolderApi;
import com.syq.play.db.entity.SongManager;
import com.syq.play.model.FolderModel;

public class FolderImpl implements FolderApi{
	private Context context;
	/**
	 * 获取首页文件夹
	 */
	public List<FolderModel> getIndexFolder() {
		int AllSong=SongManager.getInstance().getAllSongCount();
		List<FolderModel> list=new ArrayList<FolderModel>();
		FolderModel folder=new FolderModel();
		if(AllSong>0){
			folder.setIconId(R.drawable.list_icon_media);
			folder.setFolderName("全部歌曲");
			folder.setFileNum(AllSong+"首");
			list.add(folder);
			folder=new FolderModel();
			folder.setIconId(R.drawable.list_icon_artist);
			folder.setFolderName("艺术家");
			folder.setFileNum(SongManager.getInstance().getArtistCount()+"位");
			list.add(folder);
			folder=new FolderModel();
			folder.setIconId(R.drawable.list_icon_album);
			folder.setFolderName("专辑");
			folder.setFileNum(SongManager.getInstance().getAlbumtCount()+"张");
			list.add(folder);
			folder=new FolderModel();
			folder.setIconId(R.drawable.list_icon_folder);
			folder.setFolderName("文件夹");
			folder.setFileNum(SongManager.getInstance().getFolderCount()+"个");
			list.add(folder);
			folder=new FolderModel();
			folder.setIconId(R.drawable.list_icon_favourite);
			folder.setFolderName("我的最爱");
			folder.setFileNum(SongManager.getInstance().getFavoriteSongCount()+"首");
			list.add(folder);
			folder=new FolderModel();
			folder.setIconId(R.drawable.list_icon_recent);
			folder.setFolderName("最近播放");
			folder.setFileNum(SongManager.getInstance().getRecentSongCount()+"首");
			list.add(folder);
		}
		folder=new FolderModel();
		folder.setIconId(R.drawable.list_icon_new_list);
		folder.setFolderName("扫描歌曲");
		folder.setFileNum("");
		list.add(folder);
		return list;
	}
	/**
	 * 获取所有歌手
	 */
	public List<FolderModel> getAllArtist() {
		return SongManager.getInstance().getAllArtist();
	}
	/**
	 * 获取所有专辑
	 */
	public List<FolderModel> getAllAlbum() {
		return SongManager.getInstance().getAllAlbum();
	}
	/**
	 * 获取所有歌曲文件夹
	 */
	public List<FolderModel> getAllFolder() {
		return SongManager.getInstance().getAllFolder();
	}
	/**
	 * 采用单例模式，封装构造方法
	 */
	private FolderImpl(){
	}
	/**
	 * 设置context
	 * @param context
	 */
	private void setContext(Context context){
		this.context=context;
	}
	/**
	 * 类级内部类，在首次被访问时才会被初始化
	 */
	private static class SingleHolder {
		static void setContext(Context context) {
			objsingle.setContext(context);
		}

		/**
		 * 静态初始化器，有JVM来保证线程安全
		 */
		private static FolderImpl objsingle = new FolderImpl();
	}

	/**
	 * 单例，获得接口实现
	 * 
	 * @return
	 */
	public static FolderImpl getInstance(Context context) {
		SingleHolder.setContext(context);
		return SingleHolder.objsingle;
	}
}
